/*
 * LogEx a Java library for extracting log file data
 * Copyright 2012 LogEx Team.
 *
 * This program is free software. You can distribute or modify it under the 
 * terms of the GNU Lesser General Public License version 3.0 as published by  
 * the Free Software Foundation.
 *
 * This program is distributed AS IS and WITHOUT WARRANTY. OF ANY KIND,
 * INCLUDING MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, contact the Free Software Foundation, Inc.,
 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
package org.logex.utils;

import com.jcraft.jsch.UIKeyboardInteractive;
import com.jcraft.jsch.UserInfo;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

/**
 *
 * @author Sasika Chandrasekara
 */
public class MUserInfo implements UserInfo, UIKeyboardInteractive {

    String password;
    JTextField passwordField=(JTextField)new JPasswordField(20);

    public String getPassphrase() {
        return null;
    }

    public String getPassword() {
        return password;
    }

    public boolean promptPassword(String message) {
        Object[] ob = {passwordField};
        int result = JOptionPane.showConfirmDialog(null, ob, message,
        JOptionPane.OK_CANCEL_OPTION);
        if(result==JOptionPane.OK_OPTION){
            password=passwordField.getText();
            return true;
        }
        else{ return false; }
    }

    public boolean promptPassphrase(String string) {
        return true;
    }

    public boolean promptYesNo(String string) {
        Object[] options = { "yes", "no" };
        int foo = JOptionPane.showOptionDialog(null, string, "Warning",
        JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null,
                options, options[0]);
        return foo==0;
    }

    public void showMessage(String message) {
        JOptionPane.showMessageDialog(null, message);
    }

    public String[] promptKeyboardInteractive(String string, String string1, String string2, String[] strings, boolean[] blns) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

}
